unit IUIngrediente;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBCtrls, StdCtrls, Buttons, DB, DBTables, Mask;

type
  TFormIUIngrediente = class(TForm)
    LabelCliente: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Label10: TLabel;
    DBLookupComboBoxUnidade: TDBLookupComboBox;
    QueryUnidade: TQuery;
    DataSourceUnidade: TDataSource;
    Table1: TTable;
    Table1id: TIntegerField;
    Table1nome: TStringField;
    Table1nk: TStringField;
    Table1id_unidade: TIntegerField;
    Table1ID_ST: TIntegerField;
    Table1ID_TP: TIntegerField;
    Table1DT: TStringField;
    DataSource1: TDataSource;
    DBEditNome: TDBEdit;
    Label1: TLabel;
    ComboBox1: TComboBox;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    xId:integer;
  end;

var
  FormIUIngrediente: TFormIUIngrediente;
  sql:string;

implementation

uses Principal;

{$R *.dfm}

procedure TFormIUIngrediente.BitBtn1Click(Sender: TObject);
begin

    if trim(DBEditNome.Text) = '' then
    begin
         MessageDlg('Informe o Nome',mterror, [mbOk], 0);
        abort;
    end;

    if DBLookupComboBoxUnidade.KeyValue = 0 then
    begin
         MessageDlg('Informe a Unidade',mterror, [mbOk], 0);
        abort;
    end;

    if ComboBox1.ItemIndex = 0 then
       Table1Id_st.AsInteger := 2
    else
       Table1Id_st.AsInteger := 1;

       
    Table1nk.AsString := DBEditNome.Text;
    Table1nome.AsString := UpperCase(DBEditNome.Text);
    Table1Id_unidade.AsInteger := DBLookupComboBoxUnidade.KeyValue;

    Table1.Post;

    self.Close;
end;

procedure TFormIUIngrediente.FormShow(Sender: TObject);
begin

    Table1.open;
    QueryUnidade.Open;

    if xId > 0  then
    begin

       Table1.Locate('id',xId,[loPartialKey]);
       Table1.Edit;
       DBLookupComboBoxUnidade.KeyValue := Table1Id_unidade.AsInteger;

    end
    else
    begin
       Table1.Insert;
       DBLookupComboBoxUnidade.KeyValue := 0;


    end;
end;

procedure TFormIUIngrediente.BitBtn2Click(Sender: TObject);
begin
    Table1.Cancel;
end;

end.

















































